package com.huaxin.hxmodulestatisticalanalysis.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaxin.hxmodulestatisticalanalysis.dto.request.DeviceDataCollectionWideAddDTO;
import com.huaxin.hxmodulestatisticalanalysis.mapper.DeviceDataCollectionWideMapper;
import com.huaxin.hxmodulestatisticalanalysis.mapping.DeviceDataCollectionWideMapping;
import com.huaxin.hxmodulestatisticalanalysis.models.DeviceDataCollectionWide;
import com.huaxin.hxmodulestatisticalanalysis.service.DeviceDataCollectionWideService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


@Service
@RequiredArgsConstructor
@Slf4j
public class DeviceDataCollectionWideServiceImpl extends ServiceImpl<DeviceDataCollectionWideMapper, DeviceDataCollectionWide> implements DeviceDataCollectionWideService {

    //查询设备数据
    @Override
    public Page<DeviceDataCollectionWide> queryDeviceData(Integer pageNum, Integer pageSize, String deviceId, String stationNumber, String deviceType, String orgId, String familyId) {
        Page<DeviceDataCollectionWide> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<DeviceDataCollectionWide> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(deviceId)) {
            queryWrapper.eq(DeviceDataCollectionWide::getDeviceId, deviceId);
        }
        if (StringUtils.isNotBlank(stationNumber)) {
            queryWrapper.eq(DeviceDataCollectionWide::getStationNumber, stationNumber);
        }
        if (StringUtils.isNotBlank(deviceType)) {
            queryWrapper.eq(DeviceDataCollectionWide::getDeviceType, deviceType);
        }
        if (StringUtils.isNotBlank(orgId)) {
            queryWrapper.eq(DeviceDataCollectionWide::getOrgId, orgId);
        }
        if (StringUtils.isNotBlank(familyId)) {
            queryWrapper.eq(DeviceDataCollectionWide::getFamilyId, familyId);
        }
        queryWrapper.orderByDesc(DeviceDataCollectionWide::getCreatedAt);
        return page(page, queryWrapper);
    }
}
